package cn.wuzongbo.tes.controller;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import cn.wuzongbo.tes.po.ArticleCate;
import cn.wuzongbo.tes.po.ArticleCateExample;
import cn.wuzongbo.tes.po.ArticleWithBLOBs;
import cn.wuzongbo.tes.service.ArticleCateService;
import cn.wuzongbo.tes.service.ArticleService;

@Controller
@RequestMapping("/article")
public class ArticleController {
	@Autowired
	private ArticleCateService articleCateService;
	@Autowired
	private ArticleService articleService;

	@RequestMapping("/edit.do")
	public String edit(Model model,ArticleWithBLOBs articleWithBLOBs) {
		articleWithBLOBs.setReleaseDate(new Date());
		articleService.insertArticle(articleWithBLOBs);
		
		
		return "admin/article/edit";
	}

	@RequestMapping("/toedit.do")
	public String toedit(Model model) {
		
		ArticleCateExample articleCateExample = new ArticleCateExample();

		ArticleCateExample.Criteria criteria = articleCateExample.createCriteria();
		criteria.andStatusEqualTo((byte) 1);
		List<ArticleCate> articleCtaes = articleCateService.query(articleCateExample);
		
		model.addAttribute("articleCtaes", articleCtaes);

		return "admin/article/edit";
	}
}
